<?php
/*
 *author:Yangligao
 *Date:2013-10-4
 */

require '../../Config.php';

$flag = $_GET['flag'];

$menuModel = new MenuModel();
if($flag == 'display'){
	
	$pageSize = 3;
	$total = $menuModel->menu_select("count(*) as num");
	$totalCount = $total[0]['num'];
	
	$pageModel = new Page($pageSize, $totalCount);
	$start = $pageModel->getStart();
	$menuData = $menuModel->menu_select("menu_id,menu_name,menu_pic,menu_good,menu_bad,menu_count",'',"limit {$start},{$pageSize}");
	
	$pageStr = $pageModel->getPageStr();
	$smarty->assign('pageStr',$pageStr);
	$smarty->assign('menuData',$menuData);
	$smarty->display('Admin/Menu/menu.html');
}else if($flag == 'menudelete'){
	$arr['menu_id'] = $_GET['menu_id'];
	
	$res = $menuModel->menu_delete($arr);
	
	if($res){
		jump('操作成功！', $_SERVER['HTTP_REFERER']);
	}else{
		alertInfo('操作失败！！', $_SERVER['HTTP_REFERER']);
	}
}else if($flag == 'menuupdate'){
	$menu_id = $_GET['menu_id'];
	$res = $menuModel->menu_select("*","where menu_id={$menu_id}");
	
	$smarty->assign('res',$res[0]);
	$smarty->display('Admin/Menu/menuupdate.html');
}else if($flag == 'menuup'){

	unset($_POST['x']);
	unset($_POST['y']);
	if(($_FILES['pic']['name'] != '') && ($_FILES['pic']['error'] == 0) ){
		
		$upload = new Upload();
		$picPath = $upload->savePic('../Upload/menu');
		echo "111";
		$_POST['menu_pic'] = $picPath;
	}
	
	$res = $menuModel->menu_update($_POST);
	
	if($res){
		jump('操作成功！', $_SERVER['HTTP_REFERER']);
	}else{
		alertInfo('操作失败！！', $_SERVER['HTTP_REFERER']);
	}
}else if($flag == 'delMore'){
	
	if(isset($_POST['each'])){
		$keyArr = $_POST['each'];
	
	}else{
		$keyArr="";
	}
	$res = $menuModel->menu_deleteMoreByKey($keyArr);
	if($res){
		jump("记录删除成功", $_SERVER['HTTP_REFERER']);
	}else{
		jump("记录删除失败", $_SERVER['HTTP_REFERER']);
	}
}
?>
